from Crypto.Cipher import AES
import base64
import time
import json


class Encrypt:
    def __init__(self, key, iv):
        self.key = key.encode('utf-8')
        self.iv = iv.encode('utf-8')

    def pkcs7padding(self, text):
        """明文使用PKCS7填充 """
        bs = 16
        length = len(text)
        bytes_length = len(text.encode('utf-8'))
        padding_size = length if (bytes_length == length) else bytes_length
        padding = bs - padding_size % bs
        padding_text = chr(padding) * padding
        self.coding = chr(padding)
        return text + padding_text

    def aes_decrypt(self, content):
        """AES解密 """
        cipher = AES.new(self.key, AES.MODE_CBC, self.iv)
        text = cipher.decrypt(content).decode('utf-8')
        return text


# if __name__ == '__main__':
#     key = 'jo8j9wGw%6HbxfFn'
#     iv = '0123456789ABCDEF'
#
#     ts = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
#     response = '95780ba0943730051dccb5fe3918f9fe1b6f2130681f99d5620c5497aa480f138809a3aa20bf6b018ac6ca2d90bb346aa07913b77857fda5c6f21a7c3a7ff8cce625ed3925ff7990d9d4717412f545040e8be57fadb4e30d0454b0b0f4c374581cfff1bfaa7da2e25552ba8922757870a6f70499c88b134de3d6bdd44a382d1d6db35e06ecb50928c09aca75dcf29843c986ea2a7438d93585fabc04f7ebf6f11857c7df28f69f3ce9a4d88cb81b74cf76eccc697c34c91c455cb47568da214c1a10d6cb425ca90ace9d818d4a6fa76419d069a151926423efb0e3f3c22fb76e1606bfe1b9dd462fbd0dec1e73f31f4b78fffbadbdeefe0e9f0b2c7f7ceb186eb080604128b5f4ad2ac3daae35f0aa24b97dbae52605c89080cf322b7ed9969a0db14cea19aed8b8e481f4f1746ef537de586429ba6df69bf9425d09dbc69ff7b3875e6a4523d671113df3d2ba2aea50a0ee0fba2f3d1dfa9ce23a06f6e095c9ca0a196d088843c5b56baedc844cd288fe2dd85bc34e67c9be656b07b84c2155f3e26bfb702e1f48db645cab6bcfb0f2fd2666cdfef601f9fed06f2eca951aed21eb0b7b3ea78638dc0427dbfbeb9ca8dd6f08776935c16076a65798d81742b914394d12d7183f8c3b2d90e06c14413c13c9ec65658d095edce23b95c9eb2624926291e4ab0a120c2595b87d4acc224cee273a1b4650ba4d439d38b4fbbfb33b23408aa8d9070b46f28a903b5e35407b8002400d62054fce3a9ae8e5cb51c29e2f72ba9a53d2326f363efbbdc60b7beb32b2da7f8599a5dfca850c7ba31f0091860a9ef02266fa3355c798052d7bfd91b52e8496e5327ab10105cf259509125cd74eeb0aece1e3b5e0b537021542decbcc69d3afa456c9db8ddd1c3ca3fa1ebff063ffe43f07a3d50fe0314deb74da01ae768144215866ba639e632cfdc86efe4eeedfb75eead17ec4d16a8ee59af0c0309631e7547d85105af209ec3fafd1387dad21e52657c4ecf7743192c66ba33606ef13e25412841c2189b6ae4715fd45f1f842da7403f2c67b45633f7196293b8cef565bef6fbb10e88823598bf1a1449e939cfa16576a94068d0e5bcb49d1932d10be20635dfe7e2695785bac0fc7ed5f0c138f22b7ed37371316482a4a99177bd0bb74a0366ec3ebbc08630183d1dc286dc8315db09b534a25c28ccc38ef8f6ca1757925fa8fb550ec43d5c96e590575c82dfa3208bbb7bd72aeecfd63f2326576141fd56e1dfd1918b2211865ca8e4dc6552fac0b3707aa53642284fb552df5275b24b1024ae13aaa95c7994e415963756bc1118cf861b574149ad450f6bc12f157ce68852903412b5f1705685c9bda4b90d1e5ea899a6a5623d7bf70cd29c72ebcfcf2222ac48bffdeb69044208f37876045a0d0f78b331050177731faac645e577db5d14e5cee54c321b63387893cebef08b38c36397c536994f49d876c0c9a5e61f12299affa61622e3a5c456d20fc325d7922f69f9b1e31c03146727dd78222c198d59491d6553ed75c7d11fb06ae165c3478c2bbf84632aa9ac2214e1383629dfcf129b25a6a37e42ae29d95c64bca6b259dce7397e6aeec1e22505698541d294c1337f6597388a4d41643915a4f900395cb3462ed00d6cc1bd1d557e3f4dbf0078681111963798d8923b164682d81abd71333ff3bc02a84372ec8d8d914cb81c691589f234e761263c6abede259d05c5ef49c1c722562fee0627e507db6c39f169b70c6488868b376703ce655717e1d71a126beeaa349e8479d386d79477cd5fd056b963d71ebdeacfe2c44d4bdbfe4eab900372981edcb25ea66e598275f1e4c9eace70f5613a52991e7514f4632449777226a50e121854e3a116fcf344f1c290b3fc485fd2d596cd0ebc8039bc1a0d95651608873fa2bce24fff9ab0b26cd90188193b790ddc16b8f82a32476ebe8eeefb530ad63c980651de8bb7fba29d1ddf60b825e172c482e473564a2a274bf25debb42f22b6f974e141e86e81505245ea6f811858615cd8df6e2f5f3a3a53ab3672204951695d2f4b3063b6214d2b36da33f379765cf3c8a1265791af98369a3d8a348106bdb0295ad3420e56869376fed7ede913c52bb27b10e1e338993ffcc87351314cd0f1c7483681e2f8e9ab00980f0488752fe4d19bce988e67603e9afca14607254a54454d0215778f75b43a9465ae6f40e18f873e0d7efe9e74ab8a63d79a424812205d5855d604a402b0d1778570eb832ed83338f02f11527f3746ce0dc9394aed550dfbf0ea42ffbb8c0ef08b8f4ed92355d25d9c058ada9bdc5b64073884c26ead4601db38f7f579615b8a63b81c5d24bdd145326a02243e6b8e0fa67e854b0aa75108cb66d9698f70e0029e44dc22ddb1f3c7d84020c7e713ec60955b3dd99e5e74b50a286f07d5594f644d9503f605883294d395d24b70f57eab02274adcaf5ede2ffbd30d285bf1c79544632d4f8d68e38827d4db3b19e41c9f5cd118ab59fb7fc3ef47ae1562a64562270ec4878fea0bffa26892ccf9f698fac0fe12359f91022ea0cd01c595f50f58c4f9c97584505c8b2c48d34dd0abcf7d2993a1d145482a321c40d758f2bfe778134634cf340c7ff98870e6ecbee2772cab332bab2c659a928e04ef1095b44d56b79511dba4cdb1ba5364e534924c04d0c91810b6018f9a3fd04d1d7703149346f7dfa97d69c7dbd3ecc5ae691a64795a0d060f66edf8a035ce8ad5a8bb7e7dc743b8562b1b2e447dd5b8350da11d872acf5d134d2122c4bac8fdc9a119d4fb05b2606f972d17ac7b4accca430c77d3c9fa1cd0f726e802db4c2c75bf2049cea2de11ac45406707b1bac7dda34409775b85f0683515a9c502b7eb9d6c68d7e348d2c2c133a036a75b3786a668d3f678f203045e657b2d3f7dcb6e8fb1df6599f37119cdf03905bcbd951bcb4c98a7e1021b31557563f8a50029f05d1176ab159c4b4a501ca13ec3bd9f741d1ea4655fadf6f0446ad4a5d4984e1b4b6b633c6c13b293e46864c7e2b768eea85a437181487fe6053acc69800b5586ede72072e79175606df782b3ca2f09370088200928b8f7e48bab68b398a7a7db8fceea83263c416f232dc646a3febde2a86404fdbe98e7184c982e6c33fc86bc4939dbd3248fc6b25ebff2d4ca9ee8d7c8e51ad64a9e71ff4bd91a889bf7bcb744ac174cfdbf74718f70e5159e3361b1ea229066ad4ccff97ff224c080f56ce23a4f0bb17ecc6a9ed2b28b97ebee47298350be06610438cdd64d73222646baead989db16884eb367f04741292e3b5c7851fc0c91a3f2a415888a71bc5748e1cc4934d2fe3844a11be3b41f8fff2a686a671adf217ee4eed96d3e0b7b11f2c4ab2fd9032531fb9d8dd21aba0421ac16dc3ff9ea229ef9b3c4b7fdcd3c7b731345a71307d5362b5eb6ff20b5b74fc478ccde45008bee690791291f5930b0b8e395525b3806eeb029e5055eb1cbdd4ee82dbcc1863d567565a6d2a211fec9906e0ea634eb831dec102ebd3302337e6c62562496510c0eabda849e2fb92add3ea963c199e684c3e511a079e773542cecf8d689685d02e075b8ea65241340e28de261e7911528bfb7c46b53bc2db88845a27f70becee7224cc2d2d2fb7c93889163df7359371dfd3a02abb0728ae5d0cdab17ab385fd45aaca68b8b4f7156d32f3cb7c34f10a1a0201ffaa9d7a4f5a71124212015a3c83d6ed0053f525a15a9d83ba6e180fd30e5b1a545950f45db6798ff6b022713d01a677f2ead3d74c545fe9c6f6f812265253d4bd62e5f9caf5cfb849cdfb35cb7b603ed9e48b64fe8fc0fbee6dfb244498c8510ff55decbf496ce4d73d2ecb20131b2a4a89b9cf4e0caa177be0dbafdc77a0ae6969a289441085b9e26f924f41c5e4499a0bd197c28fbb70e39a2999a6b81dbb10f09aa959f3f134593bf2de467594759826a57f60c98982410bf98ce05e766400f44cec012322df7ce2f8d113380eee4d115c664dbad50452f682acf36c77dd97bf8b35239d0aa93540ef7aaff932ea5d6e18b5bfac72d9d1331628b7b701f88d29d79987e92b6eaf25667c9457db96eac634bde8944e41e73a4457bdc327cdfbc3f9e138ea0791e7309d557e3d78ff9fb2ff1d8b34e0ebd4f5eed8a1e7ee6a05f3b27e57a1be542d4e7c74713aa6cb991d9478a6f7dda56fa882a5cfddb3485f2889b7e32d6887661adeb522e7dadf3bde83c043d81d9a1c0729946f2d5db0c2bafc91e67291008560910c73de94d1581b74d40ff4c1ada347d865500d980d20d48c569b0ec4fdb536cc9dabeed2e0fd5011b94cb2ea3e35c02af5a135623b19fbd48f6012152ad984e313ca6da81fa28d61dc170297ab3c71d66c57c3be49668d4e2e37e45ab272a8eafc50bc81e8aef1e226f1e96cc0b958daafae1f15f623f36435e460955eb8cadb73a1644d76beee9ef4ae72c0ee603764e4c6108f6691d9ec047e8fc19581d680a54f6d82c1fbe9da42c73a81c90d9401169ba993e63a25a3197b630f2110433b559ef6e55b9b0a2fe4ccf490d558e2557cbf238fcc487c72f192f6678e1826a7e01fe9577024912f9693d291b9183d672c43394a8984d7a2cbb7334f66c184ce3ef5a036c09cf4350c7117ac5034a11144064dabd242b4f1429842f1274f68e65e2d92755f2aeed2668521e83c23f601b6870c65d5c21255fb7be01a14ac003b959b8c8480d4ed7db17d9b87162de71374f96c8ce19ad2f7e7caa32f7f73d1c412eb3f0086d549b06df94a973f34f2893c931d2584897b172bbe6d55eafa7bb105cba2a7fddd7bb7352afd8cd7a2a202e10c7ab2c26ed64430748a37d32884b66096b0641c942a772f5ef47e75ca7d370dea06bf7544273139c63464bc8b1bf0ad4298946234d894a97d6a92204c907d737f7de70a36870593508cc90fb2186576179294d352f412d3b51ba0c3c1c31bfef6b4238aecd3ff0bab605ec7eb2bc99eaaafeb9c0b706f8e5b3a6cb85a5fb606d33729668e9f4aa1c51b23731eeb28b0ccdc6ca68192f03ce4f63ca5876f103f79c2d3b6154ef07ba939ce96b6fa6fe853f2b009017981712d6adecdc92c3bcb6d063d0717c1a92c3d16b9e1a43469873081a34a081009e26b98bd0601bed2e3b6d64eca10fc22dd3b47ff2546059f32e22d6ffe343a38e206a9e7289252625e184954cfabb9c06617cbdb459589a7d9325ec4bea568380b84e272cdac4d82e091e99f71e0202c125a324d94c8f6573d896be104043c5aac89aa27e125af550a01cad0153a7bb64c3a8cf5195275302d6e03ebeb04832a4c89e9ba0166e47f21826e74a981582da6a6b014d0d56b3886c796b539cb250d2745b954e707675b6fe903d6d7cd942af996a3d7ce8ee0904572cc61c5caecc7bc49dc5fb804ab3e862889d22ffc82c8762a9ff7f426915f0c47862dc9aa50323f6d69764d403fd7bea8b469bdcc97e85d3a3ecd20990c9ae63663e5b63e7dc705ca5f95770dc3e2483fe02ab2a32225fde0f3cdaef8a47556792a6400bf05efdfad0b80142dd7423e0f52f51ef2d3d31f3bd244ab7df2ccca30445ea89a05710050ed39a8c94341c2d61fdb5af1b051e2559914b9bc5407d4332fce1cc7f39c7cf4ec3ee79c58e9cfb0a5c34fb602ff1675d1c69add0aa135bbf4b5c3ea25989f2bf71e071022d6c6efd93fb60e7ed8a082878b48733b5008611662000757dc015177835b27348355f1e3c1d7086767fd084fa46ed09d5ed9ae50cea826711d2813afb814d74c00abfd90a305efd93c4da8de2276e426f0c9727dc9c41dd7c67dd0d9380ee86ff9411a9255ff4cc9d36645ef7a94ca5058e7efb193e90f8ebd1aecbd4ae57686'
#     a = Encrypt(key=key, iv=iv)
#     e = bytes.fromhex(response)
#     d = a.aes_decrypt(e)
#     print("加密:", e)
#     print("解密:", d)
